package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Api(tags = "店铺相关接口")
@RequestMapping("/user/shop")
@RestController("userShopController") // 指定 bean 名称
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate<String, Integer> redisTemplate;

    // 设置店铺状态常量
    private static final String SHOP_STATUS = "SHOP_STATUS";

    /**
     * 获取店铺营业状态
     * @return 营业状态
     */
    @ApiOperation(value = "获取店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus() {
        ValueOperations<String, Integer> valueOperations = redisTemplate.opsForValue();
        Integer status = valueOperations.get(SHOP_STATUS) != null ? valueOperations.get(SHOP_STATUS) : Integer.valueOf(0);
        log.info("获取店铺营业状态：{}", status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }
}
